<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtradiobuttonlist.inc.php");
use_unit("components4phpfull/jtcheckboxlist.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class CompanyBilling extends Page
{
       public $btnCancel = null;
       public $btnSubmit = null;
       public $Image3 = null;
       public $chkParts = null;
       public $chkMiscellaneous = null;
       public $chkLabor = null;
       public $lblPercent = null;
       public $edPercent = null;
       public $chkAuto = null;
       public $JTGroupAuto = null;
       public $JTSiteTheme1 = null;

       function chkAutoJSChange($sender, $params)
       {
       ?>
       //Add your javascript code here
       if(document.CompanyBilling.chkAuto.checked == true)
       {
       document.CompanyBilling.chkLabor.disabled = false;
       document.CompanyBilling.chkMiscellaneous.disabled = false;
       document.CompanyBilling.chkParts.disabled = false;
       document.CompanyBilling.edPercent.disabled = false;
       document.CompanyBilling.edPercent.style.background =  '#FFFFFF';
       document.CompanyBilling.chkLockRate.disabled = false;
       document.CompanyBilling.chkLockAmount.disabled = false;
       }
       else
       {
       document.CompanyBilling.chkLabor.disabled = true;
       document.CompanyBilling.chkMiscellaneous.disabled = true;
       document.CompanyBilling.chkParts.disabled = true;
       document.CompanyBilling.chkLockRate.disabled = true;
       document.CompanyBilling.chkLockAmount.disabled = true;
       document.CompanyBilling.edPercent.disabled = true;
       document.CompanyBilling.edPercent.value = " ";
       document.CompanyBilling.edPercent.style.background =  '#EFEFEF';
       }

       <?php

       }



       function btnSubmitClick($sender, $params)
       {


       if ($this->chkAuto->Checked==true)
       {
       $chkAuto='1';
       }
       else
       {
       $chkAuto='0';
       }

       if ($this->chkLabor->Checked==true)
       {
       $chkLabor='1';
       }
       else
       {
       $chkLabor='0';
       }

       if ($this->chkMiscellaneous->Checked==true)
       {
       $chkMiscellaneous='1';
       }
       else
       {
       $chkMiscellaneous='0';
       }

       if ($this->chkParts->Checked==true)
       {
       $chkParts='1';
       }
       else
       {
       $chkParts='0';
       }

       if ($this->chkLockRate->Checked==true)
       {
       $chkLockRate='1';
       }
       else
       {
       $chkLockRate='0';
       }

       if ($this->chkLockAmount->Checked==true)
       {
       $chkLockAmount ='1';
       }
       else
       {
       $chkAmount='0';
       }

       $result=mysql_query("select * from company_billing_tbl where company_id='".$_SESSION['company_id']."'");
       $count=mysql_num_rows($result);
       if($count==0)
       {
       mysql_query("insert into company_billing_tbl (company_id,
       automatically_calculate,
       percent,
       labor,
       miscellaneous,
       parts)

       Values('".$_SESSION['company_id']."',
       '".$chkAuto."',
       '".$this->edPercent->Text."',
       '".$chkLabor."',
       '".$chkMiscellaneous."',
       '".$chkParts."')") or die ("insert billing - " . mysql_error());
       }
       else
       {
       mysql_query("update company_billing_tbl set
       automatically_calculate='".$chkAuto."',
       percent='".$this->edPercent->Text."',
       labor='".$chkLabor."',
       miscellaneous='".$chkMiscellaneous."',
       parts='".$chkParts."'
       where company_id='".$_SESSION['company_id']."'") or die ("update billing - " . mysql_error());
       }
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       }

       function btnCancelClick($sender, $params)
       {
       redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);
       }

       function CompanyBillingCreate($sender, $params)
       {

       $query = "select * from company_billing_tbl where company_id='".$_SESSION['company_id']."'";
       $result_show = mysql_query($query)or die("SELECT BILLING - " . mysql_error());
       $row= mysql_fetch_array($result_show);

       if($row['automatically_calculate']=='1')
       {
       $this->chkAuto->Checked=true;
       }
       else
       {
       $this->chkAuto->Checked=false;
       }

       if($row['labor']=='1')
       {
       $this->chkLabor->Checked=true;
       }
       else
       {
       $this->chkLabor->Checked=false;
       }

       if($row['miscellaneous']=='1')
       {
       $this->chkMiscellaneous->Checked=true;
       }
       else
       {
       $this->chkMiscellaneous->Checked=false;
       }

       if($row['parts']=='1')
       {
       $this->chkParts->Checked=true;
       }
       else
       {
       $this->chkParts->Checked=false;
       }


       $this->edPercent->Text = $row['percent'];

       $this->chkLabor->Enabled = false;
       $this->chkMiscellaneous->Enabled = false;
       $this->chkParts->Enabled = false;
       $this->edPercent->Enabled =false;
       $this->edPercent->Color = EFEFEF;
       }

}

global $application;

global $CompanyBilling;

//Creates the form
$CompanyBilling=new CompanyBilling($application);

//Read from resource file
$CompanyBilling->loadResource(__FILE__);

//Shows the form
$CompanyBilling->show();

?>